//package com.eco.fanliapp.utils;
//
//import com.google.gson.Gson;
//import com.google.zxing.BarcodeFormat;
//import com.google.zxing.EncodeHintType;
//import com.google.zxing.MultiFormatWriter;
//import com.google.zxing.WriterException;
//import com.google.zxing.common.BitMatrix;
//import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
//import com.qiniu.common.Zone;
//import com.qiniu.http.Response;
//import com.qiniu.storage.Configuration;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.storage.model.DefaultPutRet;
//import com.qiniu.util.Auth;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.MediaType;
//
//import javax.imageio.ImageIO;
//import java.awt.*;
//import java.awt.image.BufferedImage;
//import java.io.ByteArrayInputStream;
//import java.io.ByteArrayOutputStream;
//import java.io.UnsupportedEncodingException;
//import java.net.URL;
//import java.net.URLEncoder;
//import java.util.HashMap;
//
//public class QrUtils {
//
//    public static String createShare1(String accesskey,String secretkey,String buckets,String qnysite,  String userName, String headUrl,
//    		String qrUrl,String imgName,String imgUrl) {
//        String shareUrl = "";
//        try {
//            final String format = "png";
//
//            //定义二维码的参数
//            HashMap hints = new HashMap();
//            hints.put(EncodeHintType.CHARACTER_SET, "gbk");
//            hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
//            hints.put(EncodeHintType.MARGIN, 1);
//            String imgStr = "";
//            //生成二维码
//
//            //OutputStream stream = new OutputStreamWriter();
//
//            //URL url = new URL("http://127.0.0.1:8892/img/share2.jpg");省鸭
//            URL url = new URL(imgUrl);
//            BufferedImage image = ImageIO.read(url);
//            Graphics2D g2 = image.createGraphics();
//            /**
//             * 读取Logo图片
//             */
////            if(StringUtils.isNotEmpty(headUrl)){
////                url = new URL(headUrl);
////                BufferedImage logo = ImageIO.read(url);
////                g2.drawImage(logo, 80, 700, 80, 80, null);//绘制
////            }
//            qrUrl = getShorUrl(qrUrl);//qrUrl 二维码内容  shortUrl 转短链  为了二维码图片更容易扫
//            BufferedImage qr =  createQrImage(qrUrl,130,130);//生成二维码宽高
//            g2.drawImage(qr,311 , 1055, 130, 130, null);//绘制
////          g2.drawImage(qr, 图片左边到二维码左边的距离, 图片顶部到二维码顶部的距离, 二维码在分享图片上的宽度（带白边）,高度, null);
//
//            //往图片上绘制汉字  按需取用
////             Font f = new Font("微软雅黑",Font.PLAIN, 25);
////            Color mycolor = Color.black;//new Color(0, 0, 255);
////            g2.setColor(mycolor);
////            g2.setFont(f);
////            g2.drawString(userName, 195, 750);
//
//
//            g2.dispose();
//            image.flush();
//            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//            ImageIO.write(image, "png", outputStream);
//            String accessKey = accesskey;
//            String secretKey = secretkey;
//            String bucket = buckets;
//            Auth auth = Auth.create(accessKey, secretKey);
//            String upToken = auth.uploadToken(bucket);
//            Configuration cfg = new Configuration(Zone.zone2());
//            //...其他参数参考类注释
//            UploadManager uploadManager = new UploadManager(cfg);
//            //String key = imgName;
//            ByteArrayInputStream byteInputStream = new ByteArrayInputStream(outputStream.toByteArray());
//            Response response2 = uploadManager.put(byteInputStream, null, upToken, null, null);
//            //解析上传成功的结果
//            DefaultPutRet putRet = new Gson().fromJson(response2.bodyString(), DefaultPutRet.class);
//            shareUrl = qnysite + "/" + putRet.key;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//        return shareUrl;
//    }
//
//    private static BufferedImage createQrImage(String str, int width, int height) {
//        BitMatrix bitMatrix = null;
//        HashMap hints = new HashMap();
//        hints.put(EncodeHintType.CHARACTER_SET, "gbk");
//        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
//        hints.put(EncodeHintType.MARGIN, 1);
//        try {
//            bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, width, height, hints);
//        } catch (WriterException e) {
//            e.printStackTrace();
//        }
//        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//        for (int x = 0; x < width; x++) {
//            for (int y = 0; y < height; y++) {
//                image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
//            }
//        }
//        return image;
//    }
//
//    public static String getShorUrl(String longUrl) {
//
//        String shortUrl = null;
//
////        shortUrl = WeiBoDwzUtils.createShortUrl(longUrl);
//
//        if (shortUrl == null || "".equals(shortUrl)) {
//            shortUrl = BaiduDwzUtils.createShortUrl(longUrl, "1-year");
//        }
//        if (shortUrl == null || "".equals(shortUrl)) {
//            shortUrl = SuoImDwzUtils.createShortUrl(longUrl);
//        }
//        if (shortUrl == null || "".equals(shortUrl)) {
//            shortUrl = MrwSoDwzUtils.createShortUrl(longUrl);
//        }
//        if (shortUrl == null || "".equals(shortUrl)) {
//            shortUrl = longUrl;
//        }
//
//        return shortUrl;
//    }
//
//
//}
